package show.lmm.oauth2server.core.view.response;

import lombok.Data;

/**
 * 返回值
 */
@Data
public class ReturnHandler<T> {
    private int code;

    private String msg;

    private long timeStamp = System.currentTimeMillis();

    private T data;

    private ReturnHandler() {
    }

    public static <T> ReturnHandler<T> ok(T data) {
        return createResponseData(ResponseCode.OK.getCode(), ResponseCode.OK.getMsg(), data);
    }

    public static <T> ReturnHandler<T> error(int code, String msg) {
        return createResponseData(code, msg, null);
    }

    public static <T> ReturnHandler<T> error(ResponseCode status) {
        return createResponseData(status.getCode(), status.getMsg(), null);
    }

    public static <T> ReturnHandler<T> error(ResponseCode status, String msg) {
        return createResponseData(status.getCode(), msg, null);
    }

    public static <T> ReturnHandler<T> createResponseData(int code, String msg, T data) {
        ReturnHandler<T> rd = new ReturnHandler<>();
        rd.code = code;
        rd.msg = msg;
        rd.data = data;
        return rd;
    }
}